package com.ken.common.mysql.config;


import com.ken.common.mysql.aop.PagingAop;
import com.ken.common.mysql.aop.WebPageAop;
import com.ken.common.mysql.plugins.PagePlugin;
import com.ken.common.mysql.plugins.SQLPlugin;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@MapperScan("com.ken.data.mapper")
@EnableTransactionManagement
public class DBAutoConfiguration {

    /**
     * SQL监控插件
     * @return
     */
    @Bean
    @ConditionalOnProperty(value = "kenplugin.sql.enable", havingValue = "true", matchIfMissing = true)
    public SQLPlugin getSqlPlugin(){
        return new SQLPlugin();
    }

    /**
     * 分页插件
     * @return
     */
    @Bean
    public PagePlugin getPagePlugin(){
        return new PagePlugin();
    }

    /**
     * web层分页拦截的aop
     * @return
     */
    @Bean
    public WebPageAop getWebPageAop(){
        return new WebPageAop();
    }

    /**
     * 控制局部分页的aop
     * @return
     */
    @Bean
    public PagingAop getPagingAop(){
         return new PagingAop();
    }
}
